﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Kiiro.SiteDefinition.Core;
using Kiiro.SiteDefinition.ControlTemplates;
using System.Collections.Generic;
using Kiiro.Common.Utility;
using Kiiro.Model;
using Microsoft.SharePoint;
using Kiiro.Common.Entities;
using System.Text;
using Microsoft.SharePoint.Utilities;

namespace Kiiro.SiteDefinition.ProjectPages
{
    public partial class Documents : BasePage
    {
        public string RootFolder
        {
            get { return Request.QueryString [ "RootFolder" ] == null ? string.Empty : Request.QueryString [ "RootFolder" ]; }//Server.UrlDecode ( Request.QueryString [ "RootFolder" ] ); }
        }

        public WelcomeMessagePanel V2WelcomeMessagePanel
        {
            get { return ( WelcomeMessagePanel ) v2WelcomeMessagePanel; }
        }

        public NavigationSub NavigationSub
        {
            get { return KiiroMaster.NavigationSub; }
        }

        public Pager V2Pager
        {
            get { return ( Pager ) v2Pager; }
        }
        
        protected void Page_Load ( object sender, EventArgs e )
        {
            AddCommandButtons ( );
            AddBreadcrumb ( );

            litTitle.Text = "All Documents";
            if ( KiiroMaster.V2Header.Project != null && !string.IsNullOrEmpty ( KiiroMaster.V2Header.Project.Title ) )
            {
                litTitle.Text = KiiroMaster.V2Header.Project.Title + " - All Documents";
            }

            V2Pager.NextClick += new EventHandler ( RePopulatePage );
            V2Pager.PrevClick += new EventHandler ( RePopulatePage );
            V2Pager.EntitiesPerPageChange += new EventHandler ( RePopulatePage );
            
            if ( !IsPostBack )
            {
                PopulatePage ( true );
            }
        }

        #region Page Related Methods

        private void PopulatePage ( bool pageLoad )
        {
            ddlDestinations.Items.Clear ( );
            ddlDestinations.Items.Add ( new ListItem ( "Select the folder to move to...", "" ) );

            string currentFolder = !String.IsNullOrEmpty ( RootFolder ) ? RootFolder : "Documents";
            List<string> folderList = DocumentModel.GetAllFolders ( SiteCollectionId, ServerRelativeUrl );
            if ( folderList != null )
            {
                foreach ( string folder in folderList )
                {
                    if ( folder != currentFolder )
                    {
                        ddlDestinations.Items.Add ( new ListItem ( folder, folder ) );
                    }
                }
            }

            string folderPath = RootFolder;
            if ( folderPath == string.Empty )
            {
                folderPath = base.ServerRelativeUrl + Constants.SPListUrls.Documents;
            }

            if (folderPath != Constants.SPListNames.Discussions && folderPath != Constants.SPListNames.Work)
            {
                List<Document> documents = new List<Document>();
                if (pageLoad)
                    documents = DocumentModel.GetDocumentsByFolder(SiteCollectionId, ServerRelativeUrl, folderPath);
                else
                    documents = (List<Document>)rptDocuments.DataSource;

                List<Document> folders = new List<Document>();
                List<Document> sortedDocs = new List<Document>();
                List<Document> virtualFolders = new List<Document>();
                foreach (Document doc in documents)
                {
                    if (doc.IsFolder)
                        folders.Add(doc);
                    else
                        sortedDocs.Add(doc);
                }

                #region Virtual work/discussion folders

                if (string.IsNullOrEmpty(RootFolder) || RootFolder == Constants.SPListNames.Documents)
                {
                    int attachmentCount = AttachmentModel.GetAttachmentCount ( Constants.SPListNames.Discussions, SiteCollectionId, ServerRelativeUrl );
                    if ( attachmentCount > 0 )
                    {
                        Document attachmentFolder = new Document ( );
                        attachmentFolder.IsFolder = true;
                        attachmentFolder.Contains = attachmentCount;
                        attachmentFolder.Url = Constants.SPListNames.Discussions;
                        attachmentFolder.IconUrl = "/_layouts/images/Kiiro/icon-attachment.png";
                        attachmentFolder.Title = "Discussion Attachments";
                        attachmentFolder.Id = 0;
                        virtualFolders.Add ( attachmentFolder );
                    }

                    attachmentCount = AttachmentModel.GetAttachmentCount ( Constants.SPListNames.Work, SiteCollectionId, ServerRelativeUrl );
                    if ( attachmentCount > 0 )
                    {
                        Document attachmentFolder = new Document ( );
                        attachmentFolder.IsFolder = true;
                        attachmentFolder.Contains = attachmentCount;
                        attachmentFolder.Url = Constants.SPListNames.Work;
                        attachmentFolder.IconUrl = "/_layouts/images/Kiiro/icon-attachment.png";
                        attachmentFolder.Title = "Task and Issue Attachments";
                        attachmentFolder.Id = 0;
                        virtualFolders.Add ( attachmentFolder );
                    }
                }

                #endregion

                if (sortedDocs.Count >= 0)
                {
                    SortList(sortedDocs, folders);
                    sortedDocs.InsertRange(0, virtualFolders);

                    V2Pager.PopulatePager(sortedDocs.Count, Constants.PagerEntity.Documents);                    

                    rptDocuments.DataSource = sortedDocs.GetRange(V2Pager.PagingIndex, V2Pager.DisplayedCount);
                    rptDocuments.DataBind();
                }
                else
                    documentContent.Attributes.Add("class", "panel-content");

                if (rptDocuments.Items.Count > 0)
                {
                    HtmlGenericControl docDiv = (HtmlGenericControl)rptDocuments.Items[rptDocuments.Items.Count - 1].FindControl("docDiv");
                    docDiv.Attributes.Add("class", "document borderless");
                }
                else
                {
                    v2Pager.Visible = false;
                    columnHeaders.Visible = false;
                    v2WelcomeMessagePanel.Visible = true;
                    V2WelcomeMessagePanel.ShowPanel = true;
                    V2WelcomeMessagePanel.ServerRelativeUrl = ServerRelativeUrl;
                    V2WelcomeMessagePanel.RootFolder = RootFolder;
                    V2WelcomeMessagePanel.ShowHidePanel(Constants.PagerEntity.Documents, PermissionBitsDocuments);
                }
            }
            else 
            {
                List<Attachment> attachments = AttachmentModel.GetAttachments(RootFolder, SiteCollectionId, ServerRelativeUrl);

                if (attachments != null && attachments.Count > 0)
                {
                    attachmentContent.Visible = true;
                    documentContent.Visible = false;
                    actions.Visible = false;
                    userheader.Attributes.Add("class", "attachments-header");

                    lbCreatedSort.Text = RootFolder == Constants.SPListNames.Discussions ? "Discussion" : "Work";
                    lbModifiedSort.Text = "Created";
                    
                    SortAttachmentsList(attachments);
                    
                    V2Pager.PopulatePager(attachments.Count, Constants.PagerEntity.Documents);

                    rptAttachments.DataSource = attachments.GetRange(V2Pager.PagingIndex, V2Pager.DisplayedCount);
                    rptAttachments.DataBind();

                    if (rptAttachments.Items.Count > 0)
                    {
                        HtmlGenericControl docDiv = (HtmlGenericControl)rptAttachments.Items[rptAttachments.Items.Count - 1].FindControl("docDiv");
                        docDiv.Attributes.Add("class", "document borderless");
                    }
                }
                else
                {
                    Response.Redirect(base.ServerRelativeUrl + Constants.SPListUrls.Documents);
                }
            }
        }

        private void AddCommandButtons ( )
        {
            if (RootFolder != Constants.SPListNames.Discussions && RootFolder != Constants.SPListNames.Work)
            {
                List<LinkButton> buttons = new List<LinkButton>();

                if (PermissionBitsDocuments[0])
                {
                    LinkButton btnCreateFolder = new LinkButton();
                    btnCreateFolder.Text = "Create A Folder";
                    btnCreateFolder.Attributes.Add("class", "icon-add");
                    btnCreateFolder.Click += new EventHandler(btnCreateFolder_Click);
                    NavigationSub.Commands.Add(btnCreateFolder);

                    LinkButton btnUploadDocument = new LinkButton();
                    btnUploadDocument.Text = "Upload A Document";
                    btnUploadDocument.Attributes.Add("class", "icon-add");
                    btnUploadDocument.Click += new EventHandler(btnUploadDocument_Click);
                    NavigationSub.Commands.Add(btnUploadDocument);
                }
            }
        }

        private void AddBreadcrumb()
        {
            StringBuilder sb = new StringBuilder ( "<ul class='left'>" );
            string currentFolderTitle = string.Empty;
            if ( RootFolder != string.Empty )
            {
                if (RootFolder != Constants.SPListNames.Discussions && RootFolder != Constants.SPListNames.Work)
                {
                    string[] folders = RootFolder.Split('/');
                    for (int i = 0; i < folders.Length; i++)
                    {
                        currentFolderTitle = folders[i];
                        if (currentFolderTitle.Length > 25)
                            currentFolderTitle = currentFolderTitle.Substring(0, 25) + "...";

                        string link = ServerRelativeUrl + "/Documents.aspx?RootFolder=";
                        for (int urlIndex = 0; urlIndex <= i; urlIndex++)
                        {
                            link += Server.UrlEncode(folders[urlIndex]) + "/";
                        }
                        link = link.TrimEnd('/');

                        if (i != folders.Length - 1)
                            sb.Append("<li><a href=\"" + link + "\">" + folders[i] + "</a></li>");
                        else
                            sb.Append("<li class='borderless'>" + folders[i] + "</li>");
                    }
                }
                else
                {
                    currentFolderTitle = RootFolder == Constants.SPListNames.Discussions ? "Dicussion Documents" : RootFolder + " Documents";
                    string link = ServerRelativeUrl + "/Documents.aspx";
                    sb.Append("<li><a href=\"" + link + "\">" + Constants.SPListNames.Documents + "</a></li>");
                    sb.Append("<li class='borderless'>" + currentFolderTitle + "</li>");
                }
            }
            else
            {
                currentFolderTitle = "DOCUMENTS";
                sb.Append ( "<li class='borderless'>Documents</li>" );
            }
            sb.Append ( "</ul>" );
            lBreadCrumb.Text = sb.ToString ( );
        }

        protected void btnCreateFolder_Click ( object sender, EventArgs e )
        {
            if ( RootFolder != string.Empty )
                Response.Redirect ( ServerRelativeUrl + Constants.ProjectFileUrls.DocumentUpload + "?Type=1&RootFolder=" + Server.UrlEncode ( RootFolder ) );
            Response.Redirect ( ServerRelativeUrl + Constants.ProjectFileUrls.DocumentUpload + "?Type=1" );
        }

        protected void btnUploadDocument_Click ( object sender, EventArgs e )
        {
            if ( RootFolder != string.Empty )
                Response.Redirect ( ServerRelativeUrl + Constants.ProjectFileUrls.DocumentUpload + "?RootFolder=" + Server.UrlEncode ( RootFolder ) );
            Response.Redirect ( ServerRelativeUrl + Constants.ProjectFileUrls.DocumentUpload );
        }

        protected void lbDelete_Click ( object sender, EventArgs e )
        {
            Document document = new Document ( );

            string [ ] cmdArgs = ( ( LinkButton ) sender ).CommandArgument.Split ( ';' );
            document.Id = Convert.ToInt32 ( cmdArgs [ 0 ] );
            document.Version = Convert.ToInt32 ( cmdArgs [ 1 ] );
            document.Url = Convert.ToString ( cmdArgs [ 2 ] );

            document.EditType = EditType.Deleted;

            DocumentModel.Save ( document, null, CurrentUser, SiteCollectionId, ServerRelativeUrl );

            if ( document.TitleMessage.Count > 0 )
            {
                ErrorsList errorsList = ( ErrorsList ) Page.Master.FindControl ( "v2ErrorsList" );
                errorsList.ErrorMessages.Add ( FormattingHelpers.GetErrorMessageText ( document.TitleMessage ) );
            }

            PopulatePage ( true );
        }

        protected void rptDocuments_ItemDataBound ( object sender, RepeaterItemEventArgs e )
        {
            Document doc = ( Document ) e.Item.DataItem;

            // document link column
            Literal docLink = ( Literal ) e.Item.FindControl ( "docLink" );
            string extension = doc.IsFolder ? "" : doc.Title.Substring ( doc.Title.LastIndexOf ( "." ) + 1 );
            string folderDetails = " &nbsp;| " + doc.Contains + ( doc.Contains == 1 ? " Item" : " Items" );
            string docUrl;
            string onClick = "";
            if ( doc.IsFolder )
            {
                docUrl = SPContext.Current.Web.Url + "/Documents.aspx?RootFolder=" + Server.UrlEncode ( doc.Url );
            }
            else
            {
                string absUrl = SPHelpers.GetHostHeader ( Request ) + ServerRelativeUrl;

                docUrl = absUrl + "/" + doc.Url;

                bool canEdit = doc.IsProjectPlan ? PermissionBitsProjectPlanFile [ 2 ] : true;
                onClick = SPHelpers.GenerateDocumentOnClick ( docUrl, extension, canEdit, absUrl );               
            }

            string iconInfo = string.Format ( "<h2><img src='{0}' />", doc.IconUrl );
            if ( doc.IsProjectPlan )
                iconInfo += "<img src='_layouts/images/Kiiro/icon-lock.png' alt='Locked to Project Settings' />";
            string anchor = string.Format ( "<a href=\"{0}\" onclick=\"{1}\">{2}</a>", docUrl, onClick, doc.Title );
            string docInfo = ( doc.IsFolder ? folderDetails : " &nbsp;| " + FormattingHelpers.LongBytesToDisplaySize ( doc.FileLength ) ) + "</h2>";
            docLink.Text = iconInfo + anchor + docInfo;

            // created by column
            Literal createdInfo = ( Literal ) e.Item.FindControl ( "createdInfo" );
            if ( !doc.IsFolder )
            {
                string link = string.Empty;
                string dateText = string.Empty;
                string userDisplayUrl = ServerRelativeUrl + Constants.PortalFileUrls.UserDisplay;
                if (doc.CreatedBy != null)
                    link = string.Format ( "<a href='{0}?Id={1}'>{2}</a><br />",
                        userDisplayUrl, doc.CreatedBy.SPUserId, SPHelpers.ConvertHtmlToKiiroSafeText ( doc.CreatedBy.FullName ) );
                if (doc.CreatedDate != null)
                    dateText = FormattingHelpers.DateTimeToDisplayDateString ( doc.CreatedDate );

                createdInfo.Text = link + dateText;
            }

            // modified by column
            Literal updatedInfo = ( Literal ) e.Item.FindControl ( "updatedInfo" );
            if ( !doc.IsFolder )
            {
                string link = string.Empty;
                string dateText = string.Empty;
                string userDisplayUrl = ServerRelativeUrl + Constants.PortalFileUrls.UserDisplay;
                if ( doc.ModifiedBy != null )
                    link = string.Format ( "<a href='{0}?Id={1}'>{2}</a><br />",
                        userDisplayUrl, doc.ModifiedBy.SPUserId, SPHelpers.ConvertHtmlToKiiroSafeText ( doc.ModifiedBy.FullName ) );
                if ( doc.ModifiedDate != null )
                    dateText = FormattingHelpers.DateTimeToDisplayDateString ( doc.ModifiedDate );

                updatedInfo.Text = link + dateText;
            }

            if ( PermissionBitsDocuments [ 2 ] )
            {
                // move link
                if ( !doc.IsProjectPlan && doc.Id > 0 )
                {
                    HtmlGenericControl liMove = ( HtmlGenericControl ) e.Item.FindControl ( "liMove" );
                    liMove.Visible = true;

                    HyperLink lnkMove = ( HyperLink ) e.Item.FindControl ( "lnkMove" );
                    lnkMove.Attributes.Add ( "docId", doc.Id.ToString ( ) );

                    lnkMove.Attributes.Add ( "path", doc.Url );

                    lnkMove.Attributes.Add ( "isFolder", doc.IsFolder.ToString().ToLower() );
                }

                // history link
                Literal historyLink = ( Literal ) e.Item.FindControl ( "historyLink" );
                if ( !doc.IsFolder )
                    historyLink.Text = "<li class='borderless'><a href=\"DocumentHistory.aspx?Id=" + doc.Id + "&docUrl=" + ServerRelativeUrl + "/" + Server.UrlEncode ( doc.Url ) + "&Source=" + Server.UrlEncode ( Request.Url.PathAndQuery ) + "\">History</a></li>";

                // rename link
                if ( !doc.IsProjectPlan && doc.Id > 0)
                {
                    HtmlGenericControl liRename = ( HtmlGenericControl ) e.Item.FindControl ( "liRename" );
                    liRename.Visible = true;
                    if ( doc.IsFolder ) liRename.Attributes.Add ( "class", "borderless" );

                    HyperLink lnkRename = ( HyperLink ) e.Item.FindControl ( "lnkRename" );
                    lnkRename.Attributes.Add ( "docId", doc.Id.ToString ( ) );

                    string title = doc.Title.Contains ( "." ) ? doc.Title.Substring ( 0, doc.Title.LastIndexOf ( '.' ) ) : doc.Title;
                    lnkRename.Attributes.Add ( "docTitle", title );

                    lnkRename.Attributes.Add ( "isFolder", doc.IsFolder.ToString ( ).ToLower ( ) );
                }
            }

            if ( PermissionBitsDocuments [ 3 ] && !doc.IsProjectPlan && doc.Id > 0 )
            {
                // delete button
                LinkButton lbDelete = ( LinkButton ) e.Item.FindControl ( "lbDelete" );
                lbDelete.CommandArgument = doc.Id + ";" + doc.Version + ";" + doc.Url;
                lbDelete.Text = "Delete";
                lbDelete.OnClientClick = "return confirm('Are you sure you want to delete " + doc.Title + "?');";
            }
        }

        protected void rptAttachments_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Attachment attachment = (Attachment)e.Item.DataItem;

            // document link column
            Literal docLink = (Literal)e.Item.FindControl("docLink");
            string extension = attachment.FileName.Substring(attachment.FileName.LastIndexOf(".") + 1);            
            string onClick = "";            
            string absUrl = SPHelpers.GetHostHeader(Request) + ServerRelativeUrl;
            string attUrl = absUrl + "/" + attachment.ServerRelativeUrl; 
            bool canEdit = true;
            onClick = SPHelpers.GenerateDocumentOnClick(attUrl, extension, canEdit, absUrl);

            string iconInfo = string.Format("<h2><img src='{0}' />", attachment.IconUrl);            
            string anchor = string.Format("<a href=\"{0}\" onclick=\"{1}\">{2}</a>", attUrl, onClick, attachment.FileName);
            string docInfo = (attachment.FileLength > 0 ? "&nbsp;| " + FormattingHelpers.LongBytesToDisplaySize(attachment.FileLength) : "") + "</h2>";
            docLink.Text = iconInfo + anchor + docInfo;

            // created by column
            Literal createdInfo = (Literal)e.Item.FindControl("uploadInfo");            
            string link = string.Empty;
            string dateText = string.Empty;
            string userDisplayUrl = ServerRelativeUrl + Constants.PortalFileUrls.UserDisplay;
            if (attachment.CreatedBy != null)
                link = string.Format("<a href='{0}?Id={1}'>{2}</a><br />",
                    userDisplayUrl, attachment.CreatedBy.SPUserId, SPHelpers.ConvertHtmlToKiiroSafeText(attachment.CreatedBy.FullName));
            if (attachment.CreatedDate != null)
                dateText = FormattingHelpers.DateTimeToDisplayDateString(attachment.CreatedDate);

            createdInfo.Text = link + dateText;            

            // owner column
            Literal itemInfo = (Literal)e.Item.FindControl("itemInfo");
            link = null;
            string itemTitle = string.Empty;
            string itemDisplayUrl = ServerRelativeUrl + "/Display" + attachment.Description + ".aspx";
            string itemIcon = attachment.Description == "Discussion" ? "" : string.Format("<img src='/_layouts/images/Kiiro/label-{0}-slim.png' />", attachment.Description);
            if (attachment.Title != null)
                link = string.Format("{0}<a href='{1}?Id={2}'>{3}</a><br />", itemIcon, itemDisplayUrl, attachment.Id, SPHelpers.ConvertHtmlToKiiroSafeText(attachment.Title));

            itemInfo.Text = link;
        }

        #endregion

        #region Pager Related Methods

        private void SortList ( List<Document> sortedDocs, List<Document> folders )
        {
            createdIcon.Visible = false;
            modifiedIcon.Visible = false;
            titleIcon.Visible = false;

            Literal sortText = titleIcon;
            string sortTextTemplate = "<img src='/_layouts/images/Kiiro/icon-sort-{0}.gif' />";

            switch ( V2Pager.SortExpression )
            {
                case "Created":
                    sortText = createdIcon;
                    sortedDocs.Sort ( delegate ( Document d1, Document d2 ) { return d1.CreatedDate.CompareTo ( d2.CreatedDate ); } );
                    break;
                case "Modified":
                    sortText = modifiedIcon;
                    sortedDocs.Sort ( delegate ( Document d1, Document d2 ) { return d1.ModifiedDate.CompareTo ( d2.ModifiedDate ); } );
                    break;
                case "Title":
                default:
                    sortText = titleIcon;
                    sortedDocs.Sort ( delegate ( Document d1, Document d2 ) { return d1.Title.CompareTo ( d2.Title ); } );
                    break;
            }

            sortText.Visible = true;

            if ( V2Pager.SortDirection == SortDirection.Ascending )
            {
                sortText.Text = string.Format ( sortTextTemplate, "asc" );
            }
            else
            {
                sortText.Text = string.Format ( sortTextTemplate, "desc" );
                sortedDocs.Reverse ( );
            }

            folders.Sort ( delegate ( Document d1, Document d2 ) { return d1.Title.CompareTo ( d2.Title ); } );
            if ( V2Pager.SortDirection == SortDirection.Descending && V2Pager.SortExpression == "Title" )
                folders.Reverse ( );

            sortedDocs.InsertRange ( 0, folders );
        }

        private void SortAttachmentsList(List<Attachment> attachments)
        {
            createdIcon.Visible = false;
            modifiedIcon.Visible = false;
            titleIcon.Visible = false;

            Literal sortText = titleIcon;
            string sortTextTemplate = "<img src='/_layouts/images/Kiiro/icon-sort-{0}.gif' />";

            switch (V2Pager.SortExpression)
            {                
                case "Modified": //Created Date 
                    sortText = modifiedIcon;
                    attachments.Sort(delegate(Attachment a1, Attachment a2) { return a1.CreatedDate.CompareTo(a2.CreatedDate); });
                    break;                                
                case "Created": //Discussion / Work Item                
                    sortText = createdIcon;
                    attachments.Sort(delegate(Attachment a1, Attachment a2) { return a1.Title.CompareTo(a2.Title); });
                    break;
                case "Title": //File Name 
                default:
                    sortText = titleIcon;
                    attachments.Sort(delegate(Attachment a1, Attachment a2) { return a1.FileName.CompareTo(a2.FileName); });
                    break;
            }

            sortText.Visible = true;

            if (V2Pager.SortDirection == SortDirection.Ascending)
            {
                sortText.Text = string.Format(sortTextTemplate, "asc");
            }
            else
            {
                sortText.Text = string.Format(sortTextTemplate, "desc");
                attachments.Reverse();
            }            
        }

        private void RePopulatePage ( object sender, EventArgs e )
        {
            PopulatePage ( true );
        }

        protected void SortBy_Click ( object sender, EventArgs e )
        {
            LinkButton link = ( LinkButton ) sender;
            if ( V2Pager.SortDirection == SortDirection.Ascending && V2Pager.SortExpression == link.CommandArgument )
                V2Pager.SortDirection = SortDirection.Descending;
            else
                V2Pager.SortDirection = SortDirection.Ascending;
            V2Pager.SortExpression = link.CommandArgument;

            V2Pager.IsSortClick = true;
            if (RootFolder != "Discussions" && RootFolder != "Work")
                V2Pager.DisplayedCount = rptDocuments.Items.Count;
            else
                V2Pager.DisplayedCount = rptAttachments.Items.Count;
                
            PopulatePage ( true );
        }

        #endregion
    }
}

/*************************************************************************
 * 
 * $Log: /Internal Projects/Kiiro/Kiiro.SiteDefinition/12/TEMPLATE/FEATURES/Kiiro.ProjectPages/Documents/Documents.aspx.cs $
 * 
 * 35    2/09/10 12:48p Camerons
 * 
 * 34    2/08/10 2:28p Camerons
 * 
 * 33    2/08/10 12:00p Camerons
 * 
 * 32    1/25/10 6:10p Camerons
 * 
 * 31    1/21/10 2:40p Camerons
 * 
 * 30    1/20/10 3:04p Camerons
 * 
 * 29    1/14/10 12:46p Camerons
 * 
 * 28    1/06/10 12:39p Camerons
 * 
 * 27    12/16/09 4:05p Stefanf
 * 
 * 26    15/12/09 12:58p Adamw
 * Casee 422 renamed virtual folders to "Attached Files: " + listName
 * 
 * 25    12/02/09 12:29p Stefanf
 * 
 * 24    22/11/09 9:41p Camerons
 * 
 * 23    10/11/09 2:11p Camerons
 * 
 * 22    10/27/09 5:30p Adamw
 * accomodations for moving the plan file to the document library
 * (open/edit/version history only)
 * 
 * 21    10/26/09 9:35a Adamw
 * 
 * 20    10/23/09 5:48p Adamw
 * Case 348
 * 
 * 19    10/20/09 1:20p Adamw
 * Case 349b, to allow for + in filenames: removed URLDecoding of
 * documentUrl, added encoding of hrefs, and changed Source value on All
 * Documents to be Request.Url.PathAndQuery as relative url instead of the
 * oddly encoded Request.Url (encodes spaces as + and + as +)
 * 
 * 18    10/19/09 7:01p Adamw
 * Case 349a, wrapped href = " instead of ' to allow for ' in filenames
 * and ripple of change
 * 
 * 17    30/09/09 4:08p Camerons
 * Update all links that point to UserPages, pass User.SPUserId as the
 * ItemId so that we can safely run GetOrCreateUser
 * 
 * 16    25/09/09 10:44a Shafia
 * fixed sort method to retain page index and display correct number of
 * rows when sort is clicked.
 * 
 * 15    23/09/09 4:34p Shafia
 * implemented the new WelcomeMessagePanel user control on Projects,
 * Users, CustomLists, Work, Documents, and Discussions pages.
 * Links are being displayed based on PermissionsBits[Entity]
 * 
 * 14    21/09/09 12:42p Shafia
 * 
 * 13    18/09/09 2:33p Shafia
 * New Pager Implemented. All data binding is done on the page itself not
 * on the Pager control
 * 
 * 12    2/09/09 4:36p Camerons
 * Repair for GenerateDocOnClick
 * 
 * 11    8/31/09 4:30p Stefanf
 * 
 * 10    17/08/09 11:07a Camerons
 * Added check-in comments section
 * 
 ************************************************************************/